package com.example.anni.zhuzhoujia.tianya12345;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.ImageView;

import com.bm.library.PhotoView;
import com.example.anni.zhuzhoujia.R;

import org.xutils.image.ImageOptions;
import org.xutils.x;

/**
 * Created by yangshengwen2016 on 2016/7/5.
 */
public class BigPicture extends AppCompatActivity {
    private ViewPager mPager;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.big_picture);
        //透明状态栏
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        //透明导航栏
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
        Intent intent = getIntent();
        String img = intent.getStringExtra("img");//获取传过来的数据
        final int imgPosition = intent.getIntExtra("imgPosition", 0);//获取传过来的数据
        final String[] array_img = img.split(",");
        mPager = (ViewPager) findViewById(R.id.pager);
        mPager.setPageMargin((int) (getResources().getDisplayMetrics().density * 15));
        mPager.setAdapter(new PagerAdapter() {
            @Override
            public int getCount() {
                return array_img.length;
            }

            @Override
            public boolean isViewFromObject(View view, Object object) {
                return view == object;
            }

            @Override
            public Object instantiateItem(ViewGroup container, int position) {
//                TextView tv = (TextView) findViewById(R.id.tv);
//                tv.setText((position+1)+"/"+array_img.length);
                PhotoView view = new PhotoView(BigPicture.this);
                view.enable();
                view.setScaleType(ImageView.ScaleType.FIT_CENTER);
                ImageOptions options3 = new ImageOptions.Builder()
                        .setImageScaleType(ImageView.ScaleType.FIT_CENTER)
                        .setLoadingDrawableId(R.mipmap.loading_img)//加载过程中的等待图片
                        .setFailureDrawableId(R.mipmap.failure_img)//加载出错显示的图片
                        .build();
                x.image().bind(view, "http://tr.zzapi.gson.cn/" + array_img[position], options3);
                container.addView(view);
                view.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        finish();
                    }
                });
                return view;
            }

            @Override
            public void destroyItem(ViewGroup container, int position, Object object) {
                container.removeView((View) object);
            }
        });
        mPager.setCurrentItem(imgPosition);//设置显示指定图片
    }
}
